/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var dtGridColumns = [
    {
        id: 'id',
        title: 'ID',
        type: 'number',
        columnClass: 'text-center',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'eq'
    },
    {
        id: 'userName',
        title: '用户名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'mobilePhone',
        title: '手机号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'userType',
        title: '类型',
        type: 'string',
        headerClass: 'text-left',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'eq',
        codeTable:{
            0:$lang.useType.PLATFORM,
            1:$lang.useType.USER,
            2:$lang.useType.INVESTOR,
            3:$lang.useType.NEXTSELLER,
            4:$lang.useType.ONELEVEL,
            5:$lang.useType.TWOLEVEL,
            6:$lang.useType.THREELEVEL,
            7:$lang.useType.AGENTSELLER
        }
    },
    {
        id: 'investName',
        title: '所属上级',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'poundageDivide',
        title: '综合管理费分佣金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'deferDivide',
        title: '递延分佣金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'profitDivide',
        title: '盈利分佣金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'sellerDivide',
        title: '次销售分佣金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'totalDivide',
        title: '总计分佣金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'user/profitReport.json',
    exportURL:ncGlobal.adminRoot + 'user/profitExport.json',
    exportFileName: '结算报表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["id","userType","delFlag"],BigDecimal:["profitCount","divideScale","sellerDivide","totalDivide"] , Timestamp:["createTime"]},
    tools:'refresh|faseQuery|export[excel]',
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_del_flag'] = 1;
grid.fastQueryParameters['in_userType'] =[3,4,5,6,7];

//排序
grid.sortParameter.columnId = 'id';
grid.sortParameter.sortType = 1;
//列表结束


//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        //新增对话框初始化
        $("#addModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            var datano = button.data('no');
            var gridData = grid.sortOriginalDatas[datano];
            var modal = $(this);

        });

        $("#reportlModal").on("show.bs.modal", function (event) {
            $reportForm = $("#reportForm");
            $(".alert-danger").remove();
            $reportForm.psly().reset();
            $reportForm.find('input[name="settleStartTimeStr"]').val("");
            $reportForm.find('input[name="settleEndTimeStr"]').val("");
        });

        //结算报表时段
        $("#submit").on("click", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#reportForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var modal = $(this);
            $("#reportForm").closest('.modal').modal('hide');
            //获取接受事件的元素
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['ge_settleStartTime'] =  $('#settleStartTime').val();
            grid.fastQueryParameters['le_settleEndTime'] =  $('#settleEndTime').val();
            grid.fastQueryParameters['eq_del_flag'] = 1;
            grid.fastQueryParameters['in_userType'] =[3,4,5,6,7];
            //排序
            grid.sortParameter.columnId = 'id';
            grid.sortParameter.sortType = 1;
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });

        //编辑对话框初始化
        $("#editModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#editForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var modal = $(this);
            //获取列表框中的原始数据
            var gridData = grid.sortOriginalDatas[datano];
        });

        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['lk_user_name'] = $('#keyword').val();
            grid.fastQueryParameters['eq_del_flag'] = 1;
            grid.fastQueryParameters['in_userType'] =[3,4,5,6,7];
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();

    $("#settlement").html('<a href="#reportlModal" data-toggle="modal" class="btn btn-danger btn-sm m-r-10"><i class="fa fa-calculator"></i>&nbsp;结算报表时段&nbsp;</a>');
});

